export const nameValidator = [
  { required: true, message: '请填写此项信息' },
  () => ({
    validator(rule, value) {
      const reg = /^[a-zA-Z\u4e00-\u9fa50-9_-]{0,50}$/;
      if (!reg.test(value)) {
        // eslint-disable-next-line prefer-promise-reject-errors
        return Promise.reject('必须只包含中文，字母，下划线，中划线，长度在50个字符以内');
      }
      return Promise.resolve();
    },
  }),
];

export const propertyValidator = [
  { required: true, message: '请填写此项信息' },
  () => ({
    validator(rule, value) {
      const reg = /^[a-zA-Z]([a-zA-Z0-9_-]{0,50})$/;
      if (!reg.test(value)) {
        // eslint-disable-next-line prefer-promise-reject-errors
        return Promise.reject('只包含字母、数字、下划线、中划线，只能字母开头，长度在50个字符以内');
      }
      return Promise.resolve();
    },
  }),
];

export const descValidator = [
  () => ({
    validator(rule, value) {
      if (value && value.length > 255) {
        // eslint-disable-next-line prefer-promise-reject-errors
        return Promise.reject('长度限制为255个字符');
      }
      return Promise.resolve();
    },
  }),
];
